<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryParamsRef" :inline="true" :rules="rules">
      <el-form-item label="通道名称" v-hasPermi="[9]" prop="channelIdList">
        <el-select class="w-195" v-model="queryParams.channelIdList" placeholder="请选择" clearable style="width: 240px">
          <el-option v-for="item in channelListData" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="开始时间" prop="startDate">
        <el-date-picker v-model="queryParams.startDate" type="datetime" placeholder="Pick a Date"
          format="YYYY-MM-DD HH:mm" time-format="HH:mm" value-format="YYYY-MM-DD HH:mm" />
      </el-form-item>
      <el-form-item label="结束时间" prop="endDate">
        <el-date-picker v-model="queryParams.endDate" type="datetime" placeholder="Pick a Date"
          format="YYYY-MM-DD HH:mm" time-format="HH:mm" value-format="YYYY-MM-DD HH:mm" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="searchHandle">搜索
        </el-button>
        <el-button icon="Refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table :data="tableData" border style="width: 30%">
      <el-table-column label="通道成功率" align="center" prop="channelRate" />
    </el-table>
  </div>
</template>
<script setup>
import { channelList, successAll } from "@/api/channel/index.js";
const { proxy } = getCurrentInstance();
const total = ref(0)

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 12,
    channelIdList: [],
    startDate: '',
    endDate: '',
  },
  rules: {
    startDate: [{ type: 'date', required: true, message: "开始时间不能为空", trigger: "change" }],
    endDate: [
      { type: 'date', required: true, message: "结束时间不能为空", trigger: "change" },
    ],
    channelIdList: [
      { required: true, message: "通道必选", trigger: "blur" },
    ],
  },
});

const { queryParams, form, rules } = toRefs(data);
const channelListData = ref([]);
function getMerchantList() {
  channelList().then((res) => {

    channelListData.value = res.data.map((item) => {
      return {
        value: item.uniChannelId,
        label: item.channelName,
      };
    });
  });
}
const tableData = ref([]);
function searchHandle() {
  proxy.$refs["queryParamsRef"].validate((valid, fields) => {
    if (valid) {
      successAll(queryParams.value).then((res) => {
        tableData.value = [{ channelRate: res.data?.channelRate }];
      });
    }
  })

}
function resetQuery() {
  proxy.resetForm("queryParamsRef");
  tableData.value = [];
}
onMounted(() => {
  getMerchantList();

})

</script>
